<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
    </style>
</head>
<style>
    .huoche:before {
        content: url(../image/menu/huoche.png);
    }

    .fan:before {
        content: url(../image/menu/fan.png);
    }

    .picifahuo:before {
        content: url(../image/menu/picifahuo.png);
    }

    .ruku:before {
        content: url(../image/menu/ruku.png);
    }

    .caigouruku:before {
        content: url(../image/menu/caigouruku.png);
    }

    .shouhuoruku:before {
        content: url(../image/menu/shouhuoruku.png);
    }

    .zongchengruku:before {
        content: url(../image/menu/zongchengruku.png);
    }

    .hkruku:before {
        content: url(../image/menu/hkruku.png);
    }

    .chuku:before {
        content: url(../image/menu/chuku.png);
    }

    .zongchengchuku:before {
        content: url(../image/menu/zongchengchuku.png);
    }

    .hkchuku:before {
        content: url(../image/menu/hkchuku.png);
    }

    .kuneizhuanyi:before {
        content: url(../image/menu/kuneizhuanyi.png);
    }

    .kujianzhuanyi:before {
        content: url(../image/menu/kujianzhuanyi.png);
    }

    .cangkuxianyouliang:before {
        content: url(../image/menu/cangkuxianyouliang.png);
    }

    .xiaoshouchuku:before {
        content: url(../image/menu/xiaoshouchuku.png);
    }

    .cangkupandian:before {
        content: url(../image/menu/cangkupandian.png);
    }

    .fahuoguanli:before {
        content: url(../image/menu/fahuoguanli.png);
    }

    .fahuotuo:before {
        content: url(../image/menu/fahuotuo.png);
    }

    .fahuojiancedan:before {
        content: url(../image/menu/fahuojiancedan.png);
    }

    .fahuoguanliyouhua:before {
        content: url(../image/menu/fahuoguanliyouhua.png);
    }

    .shouhuoyanzheng:before {
        content: url(../image/menu/shouhuoyanzheng.png);
    }

    .daochangshouhuo:before {
        content: url(../image/menu/daochangshouhuo.png);
    }

    .kanbanshouhuo:before {
        content: url(../image/menu/kanbanshouhuo.png);
    }

    .yijianshouhuo:before {
        content: url(../image/menu/yijianshouhuo.png);
    }

    .andongjiaoliao:before {
        content: url(../image/menu/andongjiaoliao.png);
    }

    .peisongbeihuo:before {
        content: url(../image/menu/peisongbeihuo.png);
    }

    .xianbianshangliao:before {
        content: url(../image/menu/xianbianshangliao.png);
    }

    .queren:before {
        content: url(../image/menu/queren.png);
    }

    .shengchanshangliao:before {
        content: url(../image/menu/shengchanshangliao.png);
    }

    .chaungjianjiancedan:before {
        content: url(../image/menu/chaungjianjiancedan.png);
    }

    .jiancedanchuli:before {
        content: url(../image/menu/jiancedanchuli.png);
    }

    .wentiluru:before {
        content: url(../image/menu/wentiluru.png);
    }

    .shiyongdengji:before {
        content: url(../image/menu/shiyongdengji.png);
    }

    .daoju:before {
        content: url(../image/menu/daoju.png);
    }

    .baofei:before {
        content: url(../image/menu/baofei.png);
    }

    .dayin:before {
        content: url(../image/menu/dayin.png);
    }

    .saomiao:before {
        content: url(../image/menu/saomiao.png);
    }

    .bangding:before {
        content: url(../image/menu/bangding.png);
    }

    .gongwei:before {
        content: url(../image/menu/gongwei.png);
    }

    .gongxu:before {
        content: url(../image/menu/gongxu.png);
    }

    .wangong:before {
        content: url(../image/menu/wangong.png);
    }

    .faqi:before {
        content: url(../image/menu/faqi.png);
    }

    .renwu:before {
        content: url(../image/menu/renwu.png);
    }

    .shebeiguanli:before {
        content: url(../image/menu/shebeiguanli.png);
    }

    .muju:before {
        content: url(../image/menu/muju.png);
    }

    .jiaoyan:before {
        content: url(../image/menu/jiaoyan.png);
    }

    .tuopan:before {
        content: url(../image/menu/tuopan.png);
    }

    .songjiandan:before {
        content: url(../image/menu/songjiandan.png);
    }

    .xinhaojiankong:before {
        content: url(../image/menu/xinhaojiankong.png);
    }

    .yichang:before {
        content: url(../image/menu/yichang.png);
    }

    .yichangchaxun:before {
        content: url(../image/menu/yichangchaxun.png);
    }

    .chakan:before {
        content: url(../image/menu/chakan.png);
    }

    .geli:before {
        content: url(../image/menu/geli.png);
    }

    .zhuanhuan:before {
        content: url(../image/menu/zhuanhuan.png);
    }

    .chengpinfahuo:before {
        content: url(../image/menu/chengpinfahuo.png);
    }

    .beijianfahuo:before {
        content: url(../image/menu/beijianfahuo.png);
    }

    .barchart:before {
        content: url(../image/menu/barchart.png);
    }

    .linechart:before {
        content: url(../image/menu/linechart.png);
    }

    .piechart:before {
        content: url(../image/menu/piechart.png);
    }

    .PLC:before {
        content: url(../image/menu/PLC.png);
    }

    .choujian:before {
        content: url(../image/menu/choujian.png);
    }

    .rongqiguidang3:before {
        content: url(../image/menu/rongqiguidang3.png);
    }

    .zhiliangfengcun:before {
        content: url(../image/menu/zhiliangfengcun.png);
    }

    .rongqichaxun:before {
        content: url(../image/menu/rongqichaxun.png);
    }

    .jiebang:before {
        content: url(../image/menu/jiebang.png);
    }

    .jihuo:before {
        content: url(../image/menu/jihuo.png);
    }

    .fencengshenhe:before {
        content: url(../image/menu/fencengshenhe.png);
    }
    
    .ziyuanbangding:before {
        content: url(../image/menu/ziyuanbangding.png);
    }

    .baoyang:before {
        content: url(../image/menu/baoyang.png);
    }
    
    .peisongjieshou:before {
        content: url(../image/menu/peisongjieshou.png);
    }

    .chejian:before {
        content: url(../image/menu/chejian.png);
    }
    
    .xianghaochaxun:before {
        content: url(../image/menu/xianghaochaxun.png);
    }
    
    .heimingdan:before {
        content: url(../image/menu/heimingdan.png);
    }

    .suo:before {
        content: url(../image/menu/suo.png);
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav"
        style="background-color: #03a9f4;position:fixed;height: 3rem;padding-top: 10px; z-index: 999;" id="header">
        <div class="aui-title" id="title">
            系统选择
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:70px;">
        <div class="aui-grid" id="menuGrid2">


        </div>
    </div>

    <footer class="aui-bar aui-bar-tab" id="footer" style=" z-index: 999;">
        <div class="aui-bar-tab-item aui-active" tapmode>
            <i class="aui-iconfont aui-icon-home"></i>
            <div class="aui-bar-tab-label">首页</div>
        </div>
        <div class="aui-bar-tab-item" tapmode onclick="toPhoto()">
            <i class="aui-iconfont aui-icon-camera"></i>
            <div class="aui-bar-tab-label">拍照</div>
        </div>
        <div class="aui-bar-tab-item" tapmode onclick="toScanner()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
        <div class="aui-bar-tab-item" tapmode onclick="toMsgList()">
            <i class="aui-iconfont aui-icon-mail"></i>
            <div class="aui-bar-tab-label">消息</div>
        </div>
        <div class="aui-bar-tab-item" tapmode onclick="setPerson()">
            <i class="aui-iconfont aui-icon-my"></i>
            <div class="aui-bar-tab-label">个人中心</div>
        </div>
    </footer>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //极光
    var jpush = null;

    //初始化
    apiready = function () {

        api.addEventListener({
            name: 'loginSuccess'
        }, function (ret, err) {

            if (ret) {

                $api.html($api.byId("menuGrid2"), "");
                window.location.reload();

            } else { }
        });

        jpush = api.require('ajpush');

        jpush.setAuth({
            auth: true
        }, function (ret) {
            if (ret) {
                // alert(ret)
                // alert(ret.status)
            }
        });

        //id
        jpush.getRegistrationId(function (ret) {
            var registrationId = ret.id;
            // console.log("registrationId:" + registrationId);

            //根据用户绑定id
            saveRegistrationId(registrationId);

        });

        api.addEventListener({
            name: 'appintent'
        }, function (ret, err) {
            // alert('通知被点击，收到数据：\n' + JSON.stringify(ret)); //监听通知被点击后收到的数据
            if (ret && ret.appParam.ajpush) {

                var ajpush = ret.appParam.ajpush;
                var id = ajpush.id;
                console.log(id);
                var title = ajpush.title;
                var content = ajpush.content;
                var extra = ajpush.extra;
                console.log(extra);

                alert('通知被点击，收到数据：\n' + content);
            }
        });

        api.addEventListener({
            name: 'pause'
        }, function (ret, err) {
            onPause(); //监听应用进入后台，通知jpush暂停事件
        })

        api.addEventListener({
            name: 'resume'
        }, function (ret, err) {
            onResume(); //监听应用恢复到前台，通知jpush恢复事件
        })

        //极光推送初始化
        initJPush();

        //绑定别名
        // bindAliasAndTags();

        api.addEventListener({
            name: 'keyback'
        }, function (ret, err) {
            if (ret) {
                //alert( JSON.stringify( ret ) );
                api.confirm({
                    title: '退出提示',
                    msg: '确定要退出程序吗?',
                    buttons: ['确定', '取消']
                }, function (ret, err) {
                    var index = ret.buttonIndex;
                    if (index == 1) {
                        api.closeWidget({
                            silent: true
                        });
                    }
                });
            } else {
                alert(JSON.stringify(err));
            }
        });

        //获取菜单
        searchMenu();

    }

    //根据用户绑定ID
    function saveRegistrationId(registrationId) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/saveRegistrationId";
        var data = {
            values: {
                registrationId: registrationId,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    // console.log("registrationId绑定成功");

                    //失败
                } else if (myobj.code == "1") {
                    // console.log("registrationId绑定失败");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    //极光推送初始化
    function initJPush() {
        jpush.init(function (ret, err) {
            if (ret && ret.status) {
                // console.log('极光推送初始化：操作成功!');
            } else {
                // console.log('极光推送初始化：操作失败!');
            }
        });
    }

    //极光绑定别名
    function bindAliasAndTags() {
        var un = localStorage.getItem('un');
        var param = {
            alias: un,
            tags: []
        };
        jpush.bindAliasAndTags(param, function (ret, err) {
            console.log('极光绑定别名处理结果：\n' + JSON.stringify(ret));
        });
    }

    //极光推送-app恢复
    function onResume() {
        jpush.onResume();
        console.log('JPush onResume');
    }

    //极光推送-app暂停
    function onPause() {
        jpush.onPause();
        console.log('JPush onPause');
    }

    //获取菜单
    function searchMenu() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchMenu";
        var data = {
            values: {
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var html = "";
                    var list = eval(myobj.list);
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        // html += "<div class='aui-col-xs-3' onclick='goPage(\"" + list[i].url + "\");'>";
                        // html += "<i class='aui-iconfont aui-icon-uwm'></i>";
                        // html += "<div class='aui-grid-label'>" + list[i].title + "</div>";
                        // html += "</div>";
                        html += "<div  id='menuGrid1' style='padding-top: 5px;height:40px;width:100%;font-size: 20px;background-color: #f1eeee; padding-left: 5px;color: #2f2929;font-weight: 200;'>";
                        html += list[i].title;
                        html += "</div>";
                        html += "<div class='aui-row' style='margin-bottom: 40px;'>";
                        for (var j = 0; j < list[i].children.length; j++) {
                            html += "    <div class='aui-col-xs-3' onclick='goPage(\"" + list[i].children[j].url + "\");'>";
                            html += "    <i class='aui-iconfont " + list[i].children[j].icon + "'></i>";
                            html += "    <div class='aui-grid-label'>" + list[i].children[j].title + "</div>";
                            html += "    </div>";
                        }
                        html += "</div>";
                    }
                    // console.log("htmlhtmlhtml",html);
                    $api.html($api.byId("menuGrid2"), html);

                    //失败
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //跳转页面
    function goPage(url) {
        var arr = url.split("?");
        var name = arr[0];
        var query = {};
        if (arr.length > 1) {
            //参数
            var paramStr = arr[1];
            var paramArr = paramStr.split("&");
            for (var i = 0; i < paramArr.length; i++) {
                var params = paramArr[i].split("=");
                query[params[0]] = params[1];
            }

        }
        //打开页面
        api.openWin({
            name: name,
            url: name + '.html',
            pageParam: {
                query: query,
            }
        });
    }

    //拍照
    function toPhoto() {
        api.getPicture({
            sourceType: 'camera', //library    图片库//camera    相机         // albm  相册
            encodingType: 'jpg', //返回图片类型，jpg或png
            mediaValue: 'pic', //媒体类型，图片或视频
            destinationType: 'url', //返回数据类型，指定返回图片地址或图片经过base64编码后的字符串
            allowEdit: true, //是否可以选择图片后进行编辑，支持iOS及部分安卓手机
            //quality: 80,
            targetWidth: 400, //压缩后的图片宽度，图片会按比例适配此宽度
            targetHeight: 500, //压缩后的图片高度，图片会按比例适配此高度
            saveToPhotoAlbum: true //拍照或录制视频后是否保存到相册
        }, function (ret, err) {
            if (ret) {
                //alert( JSON.stringify( ret ) );
            } else {
                //alert( JSON.stringify( err ) );
            }
        });
    }

    //扫描
    function toScanner() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            // getEquipByCode(ret);
        });
    }

    //消息
    function toMsgList() {
        api.openWin({
            name: "msglist",
            url: "msglist.html"
        });
    }

    //个人中心
    function setPerson() {
        api.openWin({
            name: "person",
            url: "person.html"
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>